home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 1 / PC Actual CD 01.iso / f1 / mdisk25.arj / EMIMSBOX.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1994-08-31  |  5.5 KB  |  175 lines

  1.  
  2. {*******************************************************}
  3. {                                                       }
  4. {       Turbo Pascal Version 6.0                        }
  5. {       Turbo Vision Unit                               }
  6. {                                                       }
  7. {       Copyright (c) 1990 Borland International        }
  8. {                                                       }
  9. {*******************************************************}
  10.  
  11.  
  12. { Módulo de diálogos modificado para su uso con Mdiskpro y EmiApp }
  13. { modificaciones (c) Emilio David Diaus López 1994                }
  14.  
  15. Unit Emimsbox;
  16.  
  17. {$F+,O+,X+,D-,S-,L-,R-}
  18.  
  19. Interface
  20.  
  21. Uses Objects;
  22.  
  23. Const
  24.  
  25. { Message box classes }
  26.  
  27.   Mfwarning      = $0000;       { Display a Warning box }
  28.   Mferror        = $0001;       { Dispaly a Error box }
  29.   Mfinformation  = $0002;       { Display an Information Box }
  30.   Mfconfirmation = $0003;       { Display a Confirmation Box }
  31.  
  32. { Message box button flags }
  33.  
  34.   Mfyesbutton    = $0100;       { Put a Yes button into the dialog }
  35.   Mfnobutton     = $0200;       { Put a No button into the dialog }
  36.   Mfokbutton     = $0400;       { Put an OK button into the dialog }
  37.   Mfcancelbutton = $0800;       { Put a Cancel button into the dialog }
  38.  
  39.   Mfyesnocancel  = Mfyesbutton + Mfnobutton + Mfcancelbutton;
  40.                                 { Standard Yes, No, Cancel dialog }
  41.   Mfokcancel     = Mfokbutton + Mfcancelbutton;
  42.                                 { Standard OK, Cancel dialog }
  43.  
  44. { MessageBox displays the given string in a standard sized      }
  45. { dialog box. Before the dialog is displayed the Msg and Params }
  46. { are passed to FormatStr.  The resulting string is displayed   }
  47. { as a TStaticText view in the dialog.                          }
  48.  
  49. Function Messagebox(Msg: String; Params: Pointer; Aoptions: Word): Word;
  50.  
  51. { MessageBoxRec allows the specification of a TRect for the     }
  52. { message box to occupy.                                        }
  53.  
  54. Function Messageboxrect(Var R: Trect; Msg: String; Params: Pointer;
  55.   Aoptions: Word): Word;
  56.  
  57. { InputBox displays a simple dialog that allows the user to     }
  58. { type in a string.                                             }
  59.  
  60. Function Inputbox(Title: String; Alabel: String; Var S: String;
  61.   Limit: Byte): Word;
  62.  
  63. { InputBoxRect is like InputBox but allows the specification of }
  64. { a rectangle.                                                  }
  65.  
  66. Function Inputboxrect(Var Bounds: Trect; Title: String; Alabel: String;
  67.   Var S: String;  Limit: Byte): Word;
  68.  
  69. Implementation
  70.  
  71. Uses Drivers, Views, Dialogs, Emiapp;
  72.  
  73. Function Messagebox(Msg: String; Params: Pointer;
  74.   Aoptions: Word): Word;
  75. Var
  76.   R: Trect;
  77. Begin
  78.   R.Assign(0, 0, 40, 9);
  79.   R.Move((Desktop^.Size.X - R.B.X) Div 2, (Desktop^.Size.Y - R.B.Y) Div 2);
  80.   Messagebox := Messageboxrect(R, Msg, Params, Aoptions);
  81. End;
  82.  
  83. Function Messageboxrect(Var R: Trect; Msg: String; Params: Pointer;
  84.   Aoptions: Word): Word;
  85. Const
  86.   Buttonname: Array[0..3] Of String[10] =
  87.     ('~S~i', '~N~o', 'O~K~', '~C~ancelar');
  88.   Commands: Array[0..3] Of Word =
  89.     (Cmyes, Cmno, Cmok, Cmcancel);
  90.   Titles: Array[0..3] Of String[11] =
  91.     ('Advertencia','Error','Información','Confirmar');
  92. Var
  93.   I, X, Buttoncount: Integer;
  94.   Dialog: Pdialog;
  95.   Control: Pview;
  96.   T: Trect;
  97.   Buttonlist: Array[0..4] Of Pview;
  98.   S: String;
  99. Begin
  100.   Dialog := New(Pdialog,
  101.     Init(R, Titles[Aoptions And $3]));
  102.   With Dialog^ Do
  103.   Begin
  104.     R.Assign(3, 2, Size.X - 2, Size.Y - 3);
  105.     Formatstr(S, Msg, Params^);
  106.     Control := New(Pstatictext, Init(R, S));
  107.     Insert(Control);
  108.     X := -2;
  109.     Buttoncount := 0;
  110.     For I := 0 To 3 Do
  111.       If Aoptions And ($0100 Shl I) <> 0 Then
  112.       Begin
  113.         R.Assign(0, 0, 12, 2);
  114.         Control := New(Pbutton, Init(R, Buttonname[I], Commands[I],
  115.           Bfnormal));
  116.         Inc(X, Control^.Size.X + 4);
  117.         Buttonlist[Buttoncount] := Control;
  118.         Inc(Buttoncount);
  119.       End;
  120.     X := (Size.X - X) Shr 1;
  121.     For I := 0 To Buttoncount - 1 Do
  122.     Begin
  123.       Control := Buttonlist[I];
  124.       Insert(Control);
  125.       Control^.Moveto(X, Size.Y - 3);
  126.       Inc(X, Control^.Size.X + 2);
  127.     End;
  128.     Selectnext(False);
  129.   End;
  130.   Messageboxrect := Desktop^.Execview(Dialog);
  131.   Dispose(Dialog, Done);
  132. End;
  133.  
  134. Function Inputbox(Title: String; Alabel: String; Var S: String;
  135.   Limit: Byte): Word;
  136. Var
  137.   R: Trect;
  138. Begin
  139.   R.Assign(0, 0, 60, 8);
  140.   R.Move((Desktop^.Size.X - R.B.X) Div 2, (Desktop^.Size.Y - R.B.Y) Div 2);
  141.   Inputbox := Inputboxrect(R, Title, Alabel, S, Limit);
  142. End;
  143.  
  144. Function Inputboxrect(Var Bounds: Trect; Title: String; Alabel: String;
  145.   Var S: String;  Limit: Byte): Word;
  146. Var
  147.   Dialog: Pdialog;
  148.   Control: Pview;
  149.   R: Trect;
  150.   C: Word;
  151. Begin
  152.   Dialog := New(Pdialog, Init(Bounds, Title));
  153.   With Dialog^ Do
  154.   Begin
  155.     R.Assign(4 + Cstrlen(Alabel), 2, Size.X - 3, 3);
  156.     Control := New(Pinputline, Init(R, Limit));
  157.     Insert(Control);
  158.     R.Assign(2, 2, 3 + Cstrlen(Alabel), 3);
  159.     Insert(New(Plabel, Init(R, Alabel, Control)));
  160.     R.Assign(Size.X - 30, Size.Y - 4, Size.X - 20, Size.Y - 2);
  161.     Insert(New(Pbutton, Init(R, 'O~K~', Cmok, Bfdefault)));
  162.     Inc(R.A.X, 12); Inc(R.B.X, 16);
  163.     Insert(New(Pbutton, Init(R, '~C~ancelar', Cmcancel, Bfnormal)));
  164.     Inc(R.A.X, 12); Inc(R.B.X, 12);
  165.     Selectnext(False);
  166.   End;
  167.   Dialog^.Setdata(S);
  168.   C := Desktop^.Execview(Dialog);
  169.   If C <> Cmcancel Then Dialog^.Getdata(S);
  170.   Dispose(Dialog, Done);
  171.   Inputboxrect := C;
  172. End;
  173.  
  174. End.
  175.